﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 设计模式
{
    class shouji
    {

        public static void main() {
            handset_brand ab;
            ab = new handset_brand_n();
            ab.set_handset_soft(new handset_game());
            ab.run();

            ab.set_handset_soft(new handset_addresslist());
            ab.run();

            ab = new handset_brand_m();
            ab.set_handset_soft(new handset_game());
            ab.run();

            ab.set_handset_soft(new handset_addresslist());
            ab.run();

            Console.Read();

        }

    }

    class handset_soft {
        public virtual void run() { }
    }

    class handset_game : handset_soft {
        public override void run()
        {
            Console.WriteLine("运行手机游戏");
        }
    }

    class handset_addresslist : handset_soft {
        public override void run()
        {
            Console.WriteLine("运行手机通讯录");
        }
    }

    class handset_brand {
        protected handset_soft soft;

        public void set_handset_soft(handset_soft soft) {
            this.soft = soft;
        }

        public virtual void run() { }
    }

    class handset_brand_n : handset_brand {
        public override void run()
        {
            soft.run();
        }
    }

    class handset_brand_m : handset_brand
    {
        public override void run()
        {
            soft.run();
        }
    }

}
